{include_core file="m/lib/header.html" title="购物车"}
<script type="text/javascript">
      s.products="";
    </script>
{if $cart_list}
  {foreach $category_cart_list as $alipay_account=>$tmp_cart_list}
    {include file="lib/m/category_cart_list_one.html" alipay_account=$alipay_account cart_list=$tmp_cart_list promotion_list=$promotion_list promotion_sub_info=$promotion_sub_info}
  {/foreach}
{else}
<!--end buy-car-page-->
<div class="blank-buy-car">
  <div class="blank-img"><img src="{$smarty.const.STATIC_URL}/images/m2-images/blank-car.png"></div>
  <p class="p1">您的购物车现在还是空的呢</p>
  <p class="p2">现在就去选购吧</p>
  <div class="btns"><a href="{AnUrl('index')}">去逛逛</a></div>
</div>
{/if}
<!--end blank-buy-car-->
<script>
  $(function(){
    
    $('.js_relationUl').closest('.coupons').not(':first').remove();
    
    // 删除购物车商品
    $('body').on('click', '.js_cartDelete', function(){
      var skuLine = $(this).closest('li');
      var skuId   =  parseInt(skuLine.data('sku_id'));
      var isPromotion = parseInt(skuLine.data('is_promotion'));
      var goodsId = skuLine.data('goods_id');
      var pay_account_id = $(this).closest('.cartPayClass').data('pay_account_id');

      //加入检测代码
      var s=s_gi(s_account);
      s.linkTrackVars="events,products";
      s.linkTrackEvents="scRemove";
      s.events="scRemove";
      s.products=";"+goodsId;
      s.tl(this,'o','shopping cart remove');

      if (btnClick() == false) {
        return false;
      }
      showConfirm('您确定要从购物车中删除该商品吗？', function(){
        deleteCart(skuId, isPromotion, pay_account_id, function(json){
          if (json.info == 'ok') {
            skuLine.remove();
            $('.js_cartCount_'+pay_account_id).html(json.count);
            $('.js_cartPromotionInfo').html(json.promotion);

            // 删除顶部商品数量
            /*
            $('.js_topCartList').find('dl').each(function(){
              var currSkuId = $(this).attr('data-sku_id');
              var currIsPromotion  = $(this).attr('data-is_promotion');
              if (currIsPromotion == 1 && skuId == currSkuId) {
                $(this).remove();
              }
            });*/

            /*if (json.has_express > 0) {
              $('.js_freeExpressPrice').html('还需 '+json.has_express+' 元在线支付免运费');
            } else {
              $('.js_freeExpressPrice').html('');
            }*/

            if (isPromotion > 0) {
              $('.js_relationUl').children('li').each(function(){
                var currSkuId        = $(this).attr('data-sku_id');
                //var currIsPromotion  = $(this).attr('data-goods_id');
                if (skuId == currSkuId) {
                  $(this).find('input').attr('checked', false);
                  $(this).attr('data-type', 'disabled');
                  $(this).attr('data-sku_id', 0);
                }
              });
            }

            var num = parseInt(json.num);
            if (isNaN(num) || num == 0) {
              location.href = location.href;
            }

            ////$('.js_buyCartNumber').html(json.cart_num);
            // 重置明星商品
            //getStarList();
          } else if(json.info == 'reload') {
            location.href = location.href;
          } else {
            showMsg(json.info, 'error');
          }
        });
      }, function(){
        btnClick('reset');
      });
    });

    // 改变数量
    var oldSkuNum = 1;
    $('body').on('focus', '.js_cartGoodsNum',function(){
      oldSkuNum = $(this).val();
    });
    $('body').on('blur', '.js_cartGoodsNum',function(){
      var currTr  = $(this).closest('li');
      var isPromotion = $(this).data('is_promotion');
      if(isPromotion == 1) {
        return;
      }
      var pay_account_id = $(this).closest('.cartPayClass').data('pay_account_id');
      if (currTr.hasClass('disabled')) {
        $(this).val(oldSkuNum);
        return false;
      }
      var input   = $(this);
      var stock   = currTr.data('stock');
      var currNum = input.val();
      var skuId   = currTr.data('sku_id');

      if (isNaN(currNum) || currNum < 1) {
        currNum = oldSkuNum;
      }
      // if (currNum > 200) {
      //   //currNum = 200;
      //   showMsg('商品数量不能大于200');
      //   $(this).val(oldSkuNum);
      //   return;
      // }
      if (currNum == 1) {
        $('.js_goodsNumSub').addClass('sub-disabled');
      } else {
        $('.js_goodsNumSub').removeClass('sub-disabled');
      }
      if (btnClick() == false) {
        return false;
      }
      editCart(skuId, currNum, isPromotion, pay_account_id, function(json){
        if (json.info == 'ok') {
          $('.js_cartCount_'+pay_account_id).html(json.count);
          // $('.js_cartPromotionInfo').html(json.promotion);
          currTr.find('.js_currCount').html(json.curr_count);
          input.val(currNum);

          currTr.find('.gift').each(function(){
            var giftNum = $(this).data('gift_num');
            $(this).find('em').html(giftNum*currNum);
          });

          /*if (json.has_express > 0) {
            $('.js_freeExpressPrice').html('还需 '+json.has_express+' 元在线支付免运费');
          } else {
            $('.js_freeExpressPrice').html('');
          }*/

          //$('.js_buyCartNumber').html(json.cart_num);
        } else if(json.info == 'reload') {
          location.href = location.href;
        } else {
          showMsg(json.info, 'error');
          input.val(oldSkuNum);
        }
      });
    });

    // 数量+
    $('body').on('click', '.js_goodsNumAdd',function(){
      if ($(this).hasClass('sub-disabled')) {
        return false;
      }
      var currTr  = $(this).closest('li');
      if (currTr.hasClass('disabled')) {
        return false;
      }
      var stock   = currTr.data('stock');
      var skuId   = currTr.data('sku_id');
      var input   = $(this).prev().find('input');
      var currNum = parseInt(input.val());
      var oldNum  = currNum;
      var pay_account_id = $(this).closest('.cartPayClass').data('pay_account_id');
      currNum = parseInt(currNum) + 1;
      if (currNum == 0) {
        currNum = 1;
      }
      // if (currNum > 200) {
      //   //currNum = 200;
      //   showMsg('商品数量不能大于200');
      //   input.val(200);
      //   return;
      // }
      if (currNum > 1) {
        $('.js_goodsNumSub').removeClass('sub-disabled');
      }
      if (btnClick() == false) {
        return false;
      }
      editCart(skuId, currNum, 0, pay_account_id, function(json){
        if (json.info == 'ok') {
          $('.js_cartCount_'+pay_account_id).html(json.count);
          // $('.js_cartPromotionInfo').html(json.promotion);
          currTr.find('.js_currCount').html(json.curr_count);
          input.val(currNum);

          currTr.find('.gift').each(function(){
            console.log($(this).data('gift_num'));
            var giftNum = $(this).data('gift_num');
            $(this).find('em').html(giftNum*currNum);
          });

          /*if (json.has_express > 0) {
            $('.js_freeExpressPrice').html('还需 '+json.has_express+' 元在线支付免运费');
          } else {
            $('.js_freeExpressPrice').html('');
          }*/

          //$('.js_buyCartNumber').html(json.cart_num);
        } else if(json.info == 'reload') {
          location.href = location.href;
        } else {
          showMsg(json.info, 'error');
          input.val(oldNum);
        }
      });
    });

    // 数量 -
    $('body').on('click', '.js_goodsNumSub',function(){
      if ($(this).hasClass('sub-disabled')) {
        return false;
      }
      var currTr  = $(this).closest('li');
      if (currTr.hasClass('disabled')) {
        return false;
      }
      var stock   = currTr.data('stock');
      var skuId   = currTr.data('sku_id');
      var input   = $(this).next().find('input');
      var currNum = parseInt(input.val());
      var oldNum  = currNum;
      var pay_account_id = $(this).closest('.cartPayClass').data('pay_account_id');
      currNum = currNum - 1;
      if (currNum < 1) {
        currNum = 1;
      }
      if (currNum == 1) {
        $(this).addClass('sub-disabled');
      }
      if (btnClick() == false) {
        return false;
      }
      editCart(skuId, currNum, 0, pay_account_id, function(json){
        if (json.info == 'ok') {
          $('.js_cartCount_'+pay_account_id).html(json.count);
          // $('.js_cartPromotionInfo').html(json.promotion);
          currTr.find('.js_currCount').html(json.curr_count);
          input.val(currNum);

          currTr.find('.gift').each(function(){
            var giftNum = $(this).data('gift_num');
            $(this).find('em').html(giftNum*currNum);
          });

          /*if (json.has_express > 0) {
            $('.js_freeExpressPrice').html('还需 '+json.has_express+' 元在线支付免运费');
          } else {
            $('.js_freeExpressPrice').html('');
          }*/

          //$('.js_buyCartNumber').html(json.cart_num);
        } else if(json.info == 'reload') {
          location.href = location.href;
        } else {
          showMsg(json.info, 'error');
          input.val(oldNum);
        }
      });
    });

    // 添加 加价购
    var oldSlt;
    $('.js_sltDiscountGoods').on('click', function(e){
      e.preventDefault();
      var that    = $(this);
      var type    = that.attr('data-type');
      var id      = that.data('id');
      var slted   = that.attr('data-sku_id'); //已选择的sku_id
      var goodsId = that.data('goods_id');
      var skuNum  = that.data('sku_num');
      var skuId   = that.data('sku_ids');
      oldSlt      = that;
      var pay_account_id = $(this).closest('.cartPayClass').data('pay_account_id');
      if (btnClick() == false) {
        return false;
      }

      if (type != 'disabled') {
        deleteCart(slted, 1, pay_account_id, function(json){
          if (json.info == 'ok') {
            $('.js_cartCount').html(json.count);
            // $('.js_cartPromotionInfo').html(json.promotion);
            that.find('input').attr('checked', false);
            that.attr('data-type', 'disabled');
            that.attr('data-sku_id', 0);

            // 删除上方tr
            $('.js_cartListUl').find('li').each(function(){
              var currSkuId = parseInt($(this).attr('data-sku_id'));
              var currIsPromotion  = $(this).attr('data-is_promotion');
              if (currIsPromotion == 1 && slted == currSkuId) {
                $(this).remove();
              }
            });

            /*if (json.has_express > 0) {
              $('.js_freeExpressPrice').html('还需 '+json.has_express+' 元在线支付免运费');
            } else {
              $('.js_freeExpressPrice').html('');
            }*/

            //$('.js_buyCartNumber').html(json.cart_num);
          } else if(json.info == 'reload') {
            location.href = location.href;
          }
        });
        return;
      }

      if (skuNum == 1) {
        addGoodsToCart(skuId, 1, function(json){
          oldSlt.attr('data-sku_id', skuId);
          that.find('input').get(0).checked = true;
          oldSlt.attr('data-type', 'enabled');
          $('.js_cartCount').html(json.count);
          //$('.js_cartPromotionInfo').html(json.promotion);
          $('.js_cartListUl').append(json.data);
          //viewTable();

          //$('.js_buyCartNumber').html(json.cart_num);
        }, 1);
        return;
      }

      location.href = siteUrl+'/goods/sku.html?id='+goodsId+'&is_promotion=1';
      //showMsg('缺少sku选择页面');
    });


  });
  // 修改购物车
  function editCart(skuId, goodsNum, isPromotion, pay_account_id, callback)
  {
    var url = siteUrl + '/cart/modify_cart_num';
    $.post(url, { goods_num:goodsNum, sku_id:skuId, is_promotion:isPromotion, pay_id:pay_account_id }, function(data){
      if (callback) {
        callback(data);
      }
      btnClick('reset');
    }, 'json');
  }

  // 删除购物车商品
  function deleteCart(skuId, isPromotion, pay_account_id, callback)
  {
    var url = siteUrl + '/cart/delete_cart';
    $.post(url, { sku_id:skuId, is_promotion:isPromotion, pay_id:pay_account_id }, function(json){
      if (callback) {
        callback(json);
      }
      btnClick('reset');
    }, 'json');
  }
</script>
<script language="JavaScript" type="text/javascript"><!--
/* You may give each page an identifying name, server, and channel on
the next lines. */
s.pageName="Nbd:购物流程:我的购物车";
s.server=""
s.channel="Nbd"
s.pageType=""
s.prop1="Nbd:购物流程";
s.prop2="Nbd:购物流程:我的购物车";
s.prop3="Nbd:购物流程:我的购物车";
s.prop4="Nbd:购物流程:我的购物车";
/* Conversion Variables */
s.campaign=""
s.state=""
s.zip=""
s.events="scView";
s.purchaseID=""
s.eVar1=""
s.eVar2=""
s.eVar3=""
s.eVar4=""
s.eVar5=""
/************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/
var s_code=s.t();if(s_code)document.write(s_code)//--></script>
<script language="JavaScript" type="text/javascript"><!--
if(navigator.appVersion.indexOf('MSIE')>=0)document.write(unescape('%3C')+'\!-'+'-')
//--></script><noscript><img src="http://lenovochina.122.2o7.net/b/ss/lenovo-nbd-prd/1/H.26.2--NS/0"
height="1" width="1" border="0" alt="" /></noscript><!--/DO NOT REMOVE/-->
<!-- End SiteCatalyst code version: H.26.2. -->
{include_core file="m/lib/footer.html"}